package net.lab1024.sa.admin.module.business.wms.warehouse.service;

import java.util.List;

import net.lab1024.sa.admin.module.business.wms.domain.entity.WarehouseEntity;

import net.lab1024.sa.admin.module.business.wms.domain.form.WarehouseQueryForm;
import net.lab1024.sa.admin.module.business.wms.domain.form.WarehouseUpdateForm;

import net.lab1024.sa.admin.module.business.wms.warehouse.dao.WarehouseDao;
import net.lab1024.sa.admin.module.business.wms.warehouse.domain.form.WarehouseAddForm;
import net.lab1024.sa.admin.module.business.wms.warehouse.domain.vo.WarehouseVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 仓库信息表 Service
 *
 * @Author ADog
 * @Date 2025-10-17 17:25:29
 * @Copyright 1.0
 */

@Service
public class WarehouseService {

    @Resource
    private WarehouseDao warehouseDao;

    /**
     * 分页查询
     */
    public PageResult<WarehouseVO> queryPage(WarehouseQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<WarehouseVO> list = warehouseDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(WarehouseAddForm addForm) {
        WarehouseEntity warehouseEntity = SmartBeanUtil.copy(addForm, WarehouseEntity.class);
        warehouseDao.insert(warehouseEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(WarehouseUpdateForm updateForm) {
        WarehouseEntity warehouseEntity = SmartBeanUtil.copy(updateForm, WarehouseEntity.class);
        warehouseDao.updateById(warehouseEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        warehouseDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long warehouseId) {
        if (null == warehouseId){
            return ResponseDTO.ok();
        }

        warehouseDao.deleteById(warehouseId);
        return ResponseDTO.ok();
    }
}
